/* rtree.h
   this file defines the class RTree*/

#ifndef __RTREE
#define __RTREE
//------------------------------------------------------------
#include "../func/gendef.h"
//------------------------------------------------------------
class LinList;
class SortedLinList;
class Cache;
class RTNode;
class Entry;
//------------------------------------------------------------
struct TPRSortMbr
{
	int index;
	int dimension;
	int st,ed;
	float *bounces;
	float *velocity;
	float *centermbr;
	float *centervmbr;
};
//------------------------------------------------------------
class RTree : public Cacheable
{
public:
//--===on disk===--
	int dimension;                       
	int num_of_data;	  //number of moving objects                
    int num_of_dnodes;	  //number of leaf (external) nodes           
    int num_of_inodes;	  // number internal nodes               
	int root;             // block containing root node                
	bool root_is_data;    // false if tree deep >1, tree deep =  1             
	float T;			 //the tree is optimized for future interval [0, T]
	float time;			 //the current time
//--===others===--
	RTNode *root_ptr;
    bool *re_level;  
    LinList *re_data_cands; 
	LinList *deletelist;
//--===functions===--
    RTree(char *fname, Cache* c);
	RTree(char *_tfname, int _blen, Cache *_c, float _T, int _dimension);
    RTree(char *_dsfname, char *_tfname, int _blen, Cache *_c, float _T, int _dimension);
    ~RTree();
	void del_root();
	bool FindLeaf(Entry *e);
    int get_num() { return num_of_data; }
	void insert(Entry *d);
	void load_root();  
	//void rangeQuery(Entry *_q, float _st, float _ed, SortedLinList *res);
	void rangeQuery(Entry *_q, float _st, float _ed, int& _rsltcnt);
	void read_header(char *buffer);      
	void write_header(char *buffer);
	//--===added for tpr===--
	float *moving_sect(Entry *_e1, Entry *_e2, float _st, float _ed);
	void delete_entry(Entry *_olde);
};

//Globals---------------------------------------------------------
void STR_sort(int _sort_dim, Entry *_entries, int _start, int _end, int _num_of_nodes, 
			  float _S, float _V, float _s, float _alpha, float _b);
//----------------------------------------------------------------
#endif // __RTREE
